// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import VueJsonp from 'vue-jsonp'
import elementResizeDetectorMaker from 'element-resize-detector'

import 'element-ui/lib/theme-chalk/index.css'
import '@/style/base.scss';
import 'lodash';

import store from './store';
import Storage from 'storage';
import moment from 'moment';
import i18n from 'i18n';
import echarts from 'echarts';
import SystemUtil from 'utils/systemUtil';

Vue.use(ElementUI);
Vue.use(VueJsonp);
Vue.config.productionTip = false;
Vue.prototype.$moment = moment;
Vue.prototype.i18n = i18n;
Vue.prototype.echarts = echarts;

let erd = elementResizeDetectorMaker({
  strategy: "scroll"
});
Vue.prototype.erd = erd;


router.beforeEach((to, from, next) => {
  if (from.path === '/login') {
    next();
    return;
  }

  let meta = to.meta;
  if (meta !== null && meta.requireAuth) {
    if (Storage.getLocal('user') !== null) {
      next();
      return;
    }

    if (to.path === '/homeMain' && !SystemUtil.isEmpty(to.query)) {
      next();
      return;
    }

    next({
      path: '/login',
      query: {
        redirect: to.fullPath
      }
    });
  } else {
    next()
  }
});

new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
